package com.zjj;

import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.service.GenericService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class DubboConsumerDemo  {

  // 别的服务不提供接口给你,但是你还想用, 你就可以用泛华调用
  @Reference(id = "demoService", version = "default", interfaceName = "com.zjj.DemoService", generic = true)
  private GenericService genericService;


    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DubboConsumerDemo.class);
        //将DemoService强制转换成GenericService
        GenericService genericService = (GenericService) context.getBean("demoService");
        //也能调用成功
        Object result = genericService.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"你好"});
        System.out.println(result);
    }

    }
